export default class Adapter{
    constructor(){}
    showAd(){
        console.log('Adapter show ad');
    }

    save(data){
        console.log('Adapter send score');
        if(data.onSuccess){
            data.onSuccess.call(this);
        }
    }
    getFriends(){
        console.log('Adapter get friends');
    }

    share(){
        console.log('Adapter share');
    }

    login(){
        console.log('Adapter login');
    }

    loadLvlData(key){

    }

    saveLvlData(lvl,data){

    }

    freshMyScore(score){

    }

    isLocalStorageAvailable() {
        try {
            localStorage.setItem("test", "test");
            localStorage.removeItem("test");
            return "localStorage" in window && window["localStorage"] !== null;
        } catch (e) {
            return false;
        }
    }
    randomStr(len){
        var str = 'abcdefghigklmnopqrstuvwxyz1234567890';
        var chars = [];
        var slen = str.length;
        for(var i=0;i<len;i++){
            chars.push(str.charAt(Math.floor(Math.random()*slen)));
        }
        return chars.join('');
    }

    getUid(){
        if(this.isLocalStorageAvailable()){
            var uid = localStorage.getItem("uid");
            if(uid){
                return uid;
            }
            uid = this.randomStr(32);
            localStorage.setItem('uid',uid);
            return uid;
        }        
        return 0;
    }
}